package com.yc.cloneDemo.deepClone;

/**
 * Title: 深克隆实体 ，深克隆的实现依赖引用对象实现cloneable接口并重写clone方法
 * 深度克隆能复制源对象内的引用类型对象，并且在引用类型做修改时并不影响原对象的值
 * Description: <br>
 * Author:陈圆(chenyuan@bosssoft.com.cn) <br>
 * Date:2020/8/28
 */
public class User implements Cloneable{
    private Role role;

    private String name;
    private int num;

    public Role getRole() {
        return role;
    }

    public void setRole(Role role) {
        this.role = role;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    public User clone() {
        User u = null;
        try {
            u = (User) super.clone();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return u;
    }

    @Override
    public String toString() {
        return "User{" +
                "role=" + role +
                ", name='" + name + '\'' +
                ", num=" + num +
                '}';
    }
}
